package com.dkakunsi.monev.entity;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.persistence.Transient;

@Entity
@Table(name="USER")
public class User {
	public enum Role {ADMIN, OPERATOR, GUEST}
	private Role role;
	private String username;
	private String nama;
	private String instansi;
	private String password;
	
	public User() { }

	public User(Role role) {
		setRole(role);
	}

	@Id
	@Column(name="username")
	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	@Column(name="nama")
	public String getNama() {
		return nama;
	}

	public void setNama(String nama) {
		this.nama = nama;
	}

	@Column(name="password")
	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
		setRole(Role.OPERATOR);
		
		if(password.equals("KAPET"))
			setRole(Role.ADMIN);
	}

	@Column(name="instansi")
	public String getInstansi() {
		return instansi;
	}

	public void setInstansi(String instansi) {
		this.instansi = instansi;
		
		if(instansi.equals("KAPET"))
			setRole(Role.ADMIN);
	}
	
	@Transient
	public Role getRole() {
		return role;
	}

	public void setRole(Role role) {
		this.role = role;
	}
}
